<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class Order extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $exists = $this->hasTable('order');
        if(!$exists){
        $table = $this->table('order', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_unicode_ci', 'comment' => '订单' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
        $table->addColumn('user_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => null,'signed' => false,'comment' => '用户ID',])
			->addColumn('order_no', 'string', ['limit' => 20,'null' => false,'default' => null,'signed' => true,'comment' => '订单号',])
			->addColumn('goods_count', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '商品总数',])
			->addColumn('express_amount', 'decimal', ['precision' => 10,'scale' => 2,'null' => false,'default' => 0,'signed' => false,'comment' => '快递总金额',])
			->addColumn('discount_amount', 'decimal', ['precision' => 10,'scale' => 2,'null' => false,'default' => 0,'signed' => false,'comment' => '优惠总金额',])
			->addColumn('goods_amount', 'decimal', ['precision' => 10,'scale' => 2,'null' => false,'default' => 0,'signed' => false,'comment' => '商品总金额',])
			->addColumn('order_amount', 'decimal', ['precision' => 10,'scale' => 2,'null' => false,'default' => 0,'signed' => false,'comment' => '订单总金额',])
			->addColumn('serial_number', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '支付流水号',])
			->addColumn('payed', 'decimal', ['precision' => 10,'scale' => 2,'null' => true,'signed' => false,'comment' => '已支付的金额',])
			->addColumn('can_refund_price', 'decimal', ['precision' => 10,'scale' => 2,'null' => true,'signed' => false,'comment' => '可退款金额',])
			->addColumn('has_refund_price', 'decimal', ['precision' => 10,'scale' => 2,'null' => true,'signed' => false,'comment' => '已退款金额',])
			->addColumn('pay_status', 'boolean', ['null' => true,'signed' => false,'comment' => '支付状态：0 未付款、1 已付款、2 售后中、3 部分退款、4 全部退款',])
			->addColumn('express', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '物流名称',])
			->addColumn('express_no', 'string', ['limit' => 20,'null' => true,'signed' => true,'comment' => '物流单号',])
			->addColumn('user_name', 'string', ['limit' => 50,'null' => false,'default' => null,'signed' => true,'comment' => '收货人姓名',])
			->addColumn('user_mobile', 'char', ['limit' => 20,'null' => false,'default' => null,'signed' => true,'comment' => '收货人电话',])
			->addColumn('user_adds', 'string', ['limit' => 255,'null' => false,'default' => null,'signed' => true,'comment' => '收货详细地址',])
			->addColumn('remark', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '备注',])
			->addColumn('payment_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '支付时间',])
			->addColumn('ship_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '发货时间',])
			->addColumn('confirm_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '收货时间',])
			->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '状态：0 已取消、1 待付款、2 待发货、3 已发货、4 已收货、5 已评价、6 已删除',])
			->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '创建时间',])
			->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '更新时间',])
            ->create();
        }
    }
}
